<template>
	<view>
		<view class="list">
			<!-- 点击跳转动态详情 -->
			<view class="item" v-for="(t,i) in list" :key="i" @click="toDon(t)">
			<!-- <view class="item" v-for="(t,i) in list" :key="i"> -->
			<view class="l">
				<view class="img-box" >
					<image src="../../static/pages/masseg.png" mode="" class="img" v-if="t.type==4"></image>
					<image :src="t.avatar[0]" mode="" class="img i2" v-else></image>
				</view>
				<view class="txts">
					<view class="name" v-if="t.type!=4">
						<text>{{t.nickname}}</text>
					</view>
					<view class="cont">
						<text>{{t.content}}</text>
					</view>
				</view>
			</view>
				<view class="" v-if="t.type!=4">
					<image class="isint" src="../../static/pages/intb.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="none-txt">
			<text>暂无更多消息</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					// {
					// 	"user_id": null,
					// 	"avatar": null,
					// 	"nickname": null,
					// 	"sex": null,
					// 	"age": null,
					// 	"type": 4, // 4：打卡任务，1，2，3：动态消息
					// 	"content": "任务失败", // 显示内容
					// 	"image": null,
					// 	"dynamic_id": null,
					// 	"created_at": "03月16日 02:04"
					// },
					// {
					// 	"user_id": 1,
					// 	"avatar": " [\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606817526971&di=01d5b8b55e0498f917272c6c979207f5&imgtype=0&src=http%3A%2F%2Fimages.669pic.com%2Felement_pic%2F61%2F98%2F60%2F88%2Fedb68f4e99eabf5f83d8abb3194e11c5.jpg\"]",
					// 	"nickname": "我的",
					// 	"sex": 1,
					// 	"age": 12,
					// 	"type": 3,
					// 	"content": "点赞了你的动态",
					// 	"image": " [\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606817526971&di=01d5b8b55e0498f917272c6c979207f5&imgtype=0&src=http%3A%2F%2Fimages.669pic.com%2Felement_pic%2F61%2F98%2F60%2F88%2Fedb68f4e99eabf5f83d8abb3194e11c5.jpg\"]",
					// 	"created_at": "12月04日 20:32"
					// }
				],
				page: 1
			};
		},
		onLoad() {
			this.systemIsRead();
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		methods: {
			toDon(t){
				if(t.type!=4){
					if(t.dynamic_id){
						uni.navigateTo({
							url:'/pages/dynami/detail?id='+t.dynamic_id
						})
					}
				}
			},
			systemIsRead() {
				this.$utils.postrequest("/api/message/interactionIsRead", {}, res => {
					if (res.code === 200) {
						// console.log(res)
					} else {
						// console.log(res)
					}
				})
			},
			getList() {
				this.$utils.postrequest("/api/message/interactionList", {
					page: this.page
				}, res => {
					// console.log(res);
					if (res.code === 200) {
						let data = []
						res.data.forEach((item,index)=>{
							item.avatar = JSON.parse(item.avatar)
							data.push(item)
						})
						// console.log(data)
						this.list = this.list.concat(data);
						this.page++;
					} else {
						// console.log(res)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.list {
		width: 100%;
		box-sizing: border-box;
		padding: 0 30rpx;

		.item {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 24rpx 0;
			border-bottom: 1px solid #F6F5FA;
			.l{
				display: flex;
				align-items: center;
			}
			.img-box {
				
				// display: flex;
				// align-items: center;
				// justify-content: center;
				// overflow: hidden;
				// border-radius: 50%;

				.img {
					width: 88rpx;
					height: 88rpx;
					&.i2{
						border-radius: 50%;
					}
				}
			}

			.txts {
				// width: 436rpx;

				.name {
					font-size: 28rpx;
					font-family: PingFang SC;
					line-height: 32rpx;
					color: #424242;
					margin-bottom: 18rpx;
					margin-left: 20rpx;
					margin-right: 20rpx;
				}

				.cont {
					font-size: 24rpx;
					font-family: PingFang SC;
					color: #333333;
					line-height: 24rpx;
					margin-left: 20rpx;
					margin-right: 20rpx;
				}
			}

			.btn {
				width: 106rpx;
				height: 52rpx;
				// background: linear-gradient(138deg, #8478FE, #5B47FF);
				border-radius: 10rpx;
				text-align: center;
				font-size: 26rpx;
				font-family: PingFang SC;
				color: #FFFFFF;
				line-height: 52rpx;
			}
		}
	}

	.none-txt {
		text-align: center;
		color: #999;
		font-size: 26rpx;
		padding: 20rpx 0;
	}
	.isint{
		width: 15rpx;
		height: 25rpx;
	}
</style>
